package com.sc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sc.mapper.ExamMapper;
import com.sc.pojo.Exam;
import com.sc.service.ExamService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class ExamServiceImpl implements ExamService {
    @Autowired
    ExamMapper mapper;

    public PageInfo<Exam> showHistory(Integer pageNum, Integer pageSize, String name, Integer corel, Integer corer, String subject,Integer userId) {
        PageHelper.startPage(pageNum,pageSize);
        ArrayList<Exam> exams1 = new ArrayList<>();
        List<Exam> exams = mapper.showHistory(name,corel,corer,subject,userId);
        return new PageInfo<>(exams);
    }

    public PageInfo<Exam> showHistoryBack(Integer pageNum, Integer pageSize, String name, Integer corel, Integer corer, String subject) {
        PageHelper.startPage(pageNum,pageSize);
        ArrayList<Exam> exams1 = new ArrayList<>();
        List<Exam> exams = mapper.showHistoryBack(name,corel,corer,subject);
        return new PageInfo<>(exams);
    }

    @Override
    public int deleteHistory(long id) {
        System.out.println("这是要删除的id");
        int i=mapper.deleteById(id);
        System.out.println("这是要删除的："+i);
        return i;
    }

    @Override
    public int addTitleExam(Exam exam) {
        return mapper.insertSelective(exam);
    }

    @Override
    public PageInfo<Exam> examShow(Integer pageNum, Integer pageSize, String name, String subject) {
        PageHelper.startPage(pageNum,pageSize);
        List<Exam> exams = mapper.selectExamShow(name,subject);
        return new PageInfo<>(exams);
    }

    @Override
    public int deleteAllExam(Long[] ids) {
        return mapper.deleteAllExam(ids);
    }

    @Override
    public PageInfo<Exam> classExam(Integer pageNum,Integer pageSize,Integer classid,String subject) {
        PageHelper.startPage(pageNum,pageSize);
        List<Exam> exams = mapper.classExam(classid,subject);

        return new PageInfo<>(exams);
    }

    @Override
    public Exam showOne(Long id) {
        return mapper.selectOne(id);
    }

    @Override
    public int addClassExam(Long examid, Integer classid) {
        return mapper.addClassExam(examid,classid);
    }

    @Override
    public int updateType(String type) {
        return mapper.updateType(type);
    }
}
